home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACSHELL / MS1 / SHELL_SO / LAUNCH.C next >
Text File  |  1990-04-18  |  4KB  |  167 lines

  1. /*
  2.  *    MacShell Source File
  3.  *
  4.  *    Copyright (c) 1989, 1990 Suick Bay Technologies.  All rights reserved.
  5.  *
  6.  *    P.O. Box 29202
  7.  *    Mpls, MN 55429
  8.  *
  9.  *    No parts of this software may be reproduced or stored in a
  10.  *    retrieval system or transmitted in any form, or any means,
  11.  *    electronic, mechanical, photocopying, recording or otherwise,
  12.  *    without the prior written permission of Suick Bay Technologies.
  13.  *    
  14.  *    Spread the word and not the disk.
  15.  *    
  16.  *    SPK 012290    :    Initial
  17.  */
  18.  
  19. #include    "system.h"
  20. #include     <string.h>
  21. #include     <MultiFinder.h>
  22. #include    <SegmentLdr.h>
  23.  
  24. /*
  25.  *     Error codes returned by MultiFinder
  26.  */
  27.  
  28. #define MFNoMem1    -10            /*    Not enough memory to launch      */
  29. #define MFNoMem2    -11            /*    Not enough memory to launch      */
  30. #define MFUnknown    -12            /*    Unknown error                      */
  31. #define MFNoCODE0    -13            /*  CODE 0 resource is corrupt      */
  32. #define MFNoMem3    -14            /*    Not enough memory to launch      */
  33.  
  34. typedef struct
  35.     {
  36.     char    filename[ 32 ];        /*  Name of file containing app (Pascal format)      */
  37.     int16    WD;                    /*  WDRefNum of directory containing app              */
  38.     int16    MFFlags;            /*    Flags from SIZE resource                          */
  39.     int32    prefSize;            /*  Preferred MultiFinder partition size            */
  40.     int32    minSize;            /*    Minimum MultiFinder partition size                 */
  41.     } appInfo;
  42.  
  43. typedef struct    /*    SIZE resource format  */
  44.     {
  45.     int16    flags;
  46.     int32    pref;
  47.     int32    min;
  48.     } sizeRec, *sizePtr, **sizeHand;
  49.  
  50. extern int32 DefltStack : 0x322;
  51.     
  52. /*******************************************************************/
  53.  
  54. pascal OSErr MFLaunch( char *fname, long partSize, int16 volID,
  55.                 long SIZEflags, long stacksize)
  56. {
  57. Handle    save = AppParmHandle;
  58.  
  59.     AppParmHandle = NULL;
  60.  
  61.     asm {
  62.         UNLK    A6
  63.         MOVE.L    (A7)+,A2
  64.         MOVE.W    #16,-(SP)
  65.         _OSDispatch
  66.         JMP    (A2)
  67.         }
  68.  
  69.     AppParmHandle = save;
  70. }
  71.  
  72. /*******************************************************************/
  73.  
  74. OSErr         GetAppInfo( char *name, int16 WDRefNum, appInfo *infoStruct )
  75. {
  76. int16         appFile;
  77. sizeHand     sHand;
  78.     
  79.     CopyStr( name, infoStruct->filename );
  80.     infoStruct->WD = WDRefNum;
  81.     
  82.     SetResLoad( FALSE );
  83.     appFile = OpenRFPerm( infoStruct->filename, WDRefNum, fsRdPerm );
  84.     SetResLoad( TRUE );
  85.     
  86.     if( appFile == -1 )
  87.         return ResError();
  88.         
  89.     if( sHand = (sizeHand) Get1Resource('SIZE', 0 ) )
  90.         sHand = (sizeHand) Get1Resource('SIZE', -1);
  91.         
  92.     if( sHand == NULL )
  93.         {
  94. /*
  95.  *    App has no size resource, attemp an old application
  96.  */
  97.         infoStruct->MFFlags = 0;
  98.         infoStruct->prefSize = (512L*1024L);
  99.         
  100.         if((ROM85 & 0xC000) == 0)
  101.             infoStruct->prefSize += (int32) 0x8000;
  102.             
  103.         infoStruct->minSize = (384L*1024L);
  104.         }
  105.     else
  106.         {
  107.         infoStruct->MFFlags = (*sHand)->flags;
  108.         infoStruct->prefSize = (*sHand)->pref;
  109.         
  110.         if((ROM85 & 0xC000) == 0)
  111.             infoStruct->prefSize += (int32) 0x8000;
  112.             
  113.         infoStruct->minSize = (*sHand)->min;
  114.         }
  115.             
  116.     CloseResFile( appFile );
  117.     
  118.     return( noErr );
  119. }
  120.     
  121. /*******************************************************************/
  122.  
  123. OSErr     LaunchApp( appInfo *info )
  124. {
  125. OSErr err;
  126.             
  127.     err = MFLaunch(info->filename, info->prefSize+DefltStack-0x2000,
  128.             info->WD, info->MFFlags, DefltStack);
  129.     
  130.     if (err == MFNoMem1 || err == MFNoMem2 || err == MFNoMem3 )
  131.         err = MFLaunch( info->filename, info->minSize+DefltStack-0x2000,
  132.             info->WD, info->MFFlags, DefltStack );
  133.     
  134.     if (err > 0)
  135.         err = noErr;
  136.         
  137.     return err;
  138. }
  139.  
  140. /*******************************************************************/
  141.  
  142. Boolean    CanLaunch()
  143. {
  144. int32    t1, t2;    
  145.     
  146.     t1 = NGetTrapAddress( 0xA88F, ToolTrap );
  147.     t2 = NGetTrapAddress( UNIMPLEMENTED_TRAP_NUM, ToolTrap );
  148.  
  149.     return( t1 != t2 );
  150. }
  151.  
  152. OSErr    DoLaunch( char *str, int vRefNum, int32 dirID )
  153. {
  154. appInfo info;
  155. int16    wdRefNum;
  156. OSErr    err;
  157.     
  158.     err = OpenWD( vRefNum, dirID, 'sBAY', &wdRefNum );
  159.     if( !err )
  160.         {
  161.         err = GetAppInfo( str, wdRefNum, &info );
  162.         if( !err )
  163.             err = LaunchApp( &info );
  164.         }
  165.         
  166.     return( err );
  167. }